public class PartitionAroundX {
  public Node partitionAroundX(Node n, int x) {
    if(n == null)
      return null;
    Node left;
    Node right;
    
    while(n != null){
      if( x >= n.data )
        left.append(n.data);
      else if( x < n.data )
        right.append(n.data);
      
      n = n.next; 
    }
    
    if (left == null) return right;
    if (right == null) return left;
    
    Node pivotLeft = left;
    while(pivotLeft.next != null)
      pivotLeft = pivotLeft.next;
    pivotLeft.next = right;
    return left;
    }
}